package net.easyjava.third.aws.sqs;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.sqs.AmazonSQSClient;
import com.amazonaws.services.sqs.model.CreateQueueResult;
import com.amazonaws.services.sqs.model.ListQueuesResult;

/**
 * Created by wxnacy on 16/11/24.
 */
public class AWSSQSClient {
    private volatile static AWSSQSClient singleton;
    private static AWSCredentials credentials;
    private static AmazonSQSClient sqs;
    private String accessId;
    private String accessKey;
    private AWSSQSClient(final String accessId, final String accessKey) {
        this.accessId = accessId;
        this.accessKey = accessKey;
        init();
    }
    public static AWSSQSClient getInstance(final String accessId, final String accessKey) {
        if (singleton == null) {
            synchronized (AWSSQSClient.class) {
                if (singleton == null) {
                    singleton = new AWSSQSClient(accessId, accessKey);
                }
            }
        }
        return singleton;
    }

    /**
     * 初始化
     */
    private void init(){
        try{
            credentials = new BasicAWSCredentials(accessId,accessKey);
            sqs = new AmazonSQSClient(credentials);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 创建队列
     * @param queueName
     * @return
     */
    private CreateQueueResult createQueue(String queueName){
        CreateQueueResult result = sqs.createQueue(queueName);
        return result;
    }

    private void listQueues(){
        ListQueuesResult result = sqs.listQueues();
    }



}
